define([
    "dojo/_base/declare",
    "gistech/widgets/baseWidget/BaseWidget",
    "dojo/text!./templates/Template.html",
    "dojo/_base/lang",
    "dojo/topic",
    "dojo/dom-style",
    "dojo/dom-construct",
    "dojo/on",
    "dojo/_base/array",
    "dojo/_base/connect",
    "gistech/util/ajaxUtil",
    "dojo/dom-style",
    "dojo/query",
    "dojo/dom-class"
    ],
    function(declare,BaseWidget,template,lang,Topic,style,domConstruct,on,array,eventconnect,ajaxUtil,domStyle,query,domClass){
        return declare([BaseWidget],{
        templateString:template,
        constructor:function (args) {
        	this.tableData = (args.tableData!=undefined)?args.tableData:null;
        	this.columnsData=(args.columnsData!=undefined)?args.columnsData:null;
        	this.sortName=(args.sortName!=undefined)?args.sortName:"";
        	this.sortOrder=(args.sortOrder!=undefined)?args.sortOrder:"";
        	this.exportTableName=(args.exportTableName!=undefined)?args.exportTableName:"";
        	this.inherited(arguments);
        	this.selRow=null;
        },
        postCreate:function(){
            this.inherited(arguments);
            this.$table=$('#advQueryTable',this.domNode);
            this._init();
        },
        _init:function (){
        	//debugger
        	var rowColor="";
            var hoverRowColor="#f5f5f5";
            this.selRow={
                "selRowColor":"#fffccc",
                "selRowElement":null
            };
            this.$table.attr("exportfileName",this.exportTableName);
            this.$table.bootstrapTable({
                //url:dataJson1,
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                search:true,
                strictSearch:false,//不启动全匹配搜索，为模糊搜索
                idField:'id',
                clickToSelect: true,
                searchAlign:'left',
                sortName:this.sortName,
                sortOrder:this.sortOrder,
                striped:true,//是否显示行间隔色
                classes:'table table-hover',
                showToggle:true,//table/card视图的切换
                detailView:true,//显示详细信息
                showColumns:false,
                showExport: ioc.map.userInfoData.isManager==true?true:false,//是否显示导出
                exportDataType: "all",//basic', 'all', 'selected'.
                pagination:true,                   //是否显示分页（*）
                pageNumber: 1,                    //初始化加载第一页，默认第一页
                pageSize: 8,                     //每页的记录行数（*）
                pageList: [8, 15, 20, 25],       //可供选择的每页的行数（*）
                detailFormatter:function(index, row){//详细信息格式化
                    var html = [];
                    $.each(row, function (key, value) {
                            html.push('<p><b>' + key + ':</b> ' + value + '</p>');
                    });
                    return html.join('');
                },
                onClickRow:function(row,$element,field){
                    if(this.selRow.selRowElement != null ){
                        if(this.selRow.selRowElement.index() != $element.index()){
                            var selRowColor=rowColor;
                            var selRowCElement = this.selRow.selRowElement;
                            selRowCElement.css('backgroundColor',selRowColor);
                            selRowCElement.mouseover(function(){$(this).css('backgroundColor',hoverRowColor);})
                                    .mouseout(function(){$(this).css('backgroundColor',selRowColor);})
                        }else{
                            return;
                        }
                    }
                    if((($element.index()+1) & 1) != 0){// 奇数
                        rowColor="#f9f9f9";
                    }else{
                        rowColor="#ffffff";
                    }
                    $element.css('backgroundColor',this.selRow.selRowColor);
                    $element.unbind();//移除事件
                    this.selRow.selRowElement=$element;
                    
                    if(Global.currentUseFun == "advQuery"){ //高级查询
                        Topic.publish('mutiLandType_AdvQuery',{"mutiAdvQueryLandName":row.LANDTYPENAME});//mutiAdvQueryLandType
                        Topic.publish('queryBlockById_AdvQuery',{"objectId":row.OBJECTID});
                    }
                    if(Global.currentUseFun == "basicBuffer"){//缓冲区
	                    Topic.publish('bufferBlockInfo',{"landName":row.landName});
	                    Topic.publish('singleBufferBlockInfoPosition',{"blockInfoById":row.OBJECTID});
	                    
	                    Topic.publish('baseFacilityInfo',{"baseFacilityName":row.baseFacilityName});
	                    Topic.publish('singleBaseFacilityInfo',{"singBaseFacilityId":row.id});
                    }
                    
                    if(Global.currentUseFun =="govRegionStatic_landInfo"){//行政区域统计之土地信息
                    	Topic.publish('singleGovRegionBlockInfoPosition',{"blockInfoById":row.OBJECTID});
                    }
                    if(Global.currentUseFun =="govRegionStatic_followUpProject"){//行政区域统计之跟进项目
                    	Topic.publish('singleGovRegionWYTZPosition',{"singWYTZInfoById":row.OBJECTID});
                    }
                    //聚合
                    Topic.publish('clusterDetailInfo',{"clusterlandType":row.name});//聚合详细信息
                    //poi搜素定位(经纬度定位)
                    if(Global.currentUseFun == "poiSearch"){ //高级查询
                    	 Topic.publish('locatorByNS',{"attr":row});
                    }
                    //拓展地块定位
                    if(Global.currentUseFun == "landExpandSearch"){ //拓展地块定位
                         Topic.publish("queryBlockByObjectid",{"objectId":row.OBJECTID});
                   }
                    
                }.bind(this),
                onDblClickRow:function(row, $element){},
                /*onLoadSuccess:function(){
                	alert("1111");
                },*/
                //onRefreshOptions:callback,
                columns:this.columnsData,
                data:this.tableData,
                onPageChange:function(number, size){
                	
                }
            });
        },
        appendData:function(data){
        	this.$table.bootstrapTable('append', data);
        },
        startup:function(){
            this.inherited(arguments);
        }
     });
});